package Test1;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class URLDownload {
    public static void main(String[] args) throws Exception {
        //1、下载地址
        URL url = new URL("https://www.bilibili.com/video/BV1ta411y79h/?spm_id_from=333.337.search-card.all.click&vd_source=0c1ade3a93fcb106c44279021f3cf693");

        //2、连接资源
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        InputStream is = urlConnection.getInputStream();
        FileOutputStream fos = new FileOutputStream("直拍.mp4");
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
        }

        fos.close();
        is.close();
        urlConnection.disconnect();
    }
}
